<?php

/*
 * Without this helper when you switch between your default and admin module, 
 * you'll see that it uses the same layout.  One might think that prepending the second line 
 * with "default." would enable layouts specific to the module, but unfortunately it doesn't. 
 * It will use the last specified template, in our case the admin, as default. 
 * To mitigate this, we will use a controller plugin since we need access to the 
 * request object to decide which template to show.
 * 
 * My/Controller/Action/Helper/LayoutLoader.php and added following content:
 * 
 */
class My_Controller_Action_Helper_LayoutLoader extends Zend_Controller_Action_Helper_Abstract {
	
	public function preDispatch() {
		$bootstrap = $this->getActionController ()->getInvokeArg ( 'bootstrap' );
		$config = $bootstrap->getOptions ();
		$module = $this->getRequest ()->getModuleName ();
		if (isset ( $config [$module] ['resources'] ['layout'] ['layout'] )) {
			$layoutScript = $config [$module] ['resources'] ['layout'] ['layout'];
			$this->getActionController ()->getHelper ( 'layout' )->setLayout ( $layoutScript );
		}
	}

}